import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '帝可得', icon: 'el-icon-house' }
    }]
  },

  {
    path: '/workorder',
    component: Layout,
    redirect: '/workorder/operation',
    name: 'Workorder',
    meta: { title: '工单管理', icon: 'el-icon-tickets' },
    children: [
      {
        path: 'operation',
        name: 'Operation',
        component: () => import('@/views/workorder/operation'),
        meta: { title: '运营工单' }
      },
      {
        path: 'maintenance',
        name: 'Maintenance',
        component: () => import('@/views/workorder/maintenance'),
        meta: { title: '运维工单' }
      }
    ]
  },
  {
    path: '/point',
    component: Layout,
    redirect: '/point/area',
    name: 'Point',
    meta: { title: '点位管理', icon: 'el-icon-map-location' },
    children: [
      {
        path: 'area',
        name: 'Area',
        component: () => import('@/views/point/area'),
        meta: { title: '区域管理' }
      },
      {
        path: 'points',
        name: 'Points',
        component: () => import('@/views/point/points'),
        meta: { title: '点位管理' }
      },
      {
        path: 'cooperative',
        name: 'Cooperative',
        component: () => import('@/views/point/cooperative'),
        meta: { title: '合作商管理' }
      }
    ]
  },
  {
    path: '/equipment',
    component: Layout,
    redirect: '/equipment/management',
    name: 'Equipment',
    meta: { title: '设备管理', icon: 'el-icon-data-line' },
    children: [
      {
        path: 'management',
        name: 'Management',
        component: () => import('@/views/equipment/management'),
        meta: { title: '设备管理' }
      },
      {
        path: 'status',
        name: 'Status',
        component: () => import('@/views/equipment/status'),
        meta: { title: '设备状态' }
      },
      {
        path: 'devicetype',
        name: 'DeviceType',
        component: () => import('@/views/equipment/devicetype'),
        meta: { title: '设备类型管理' }
      }
    ]
  },
  {
    path: '/people',
    component: Layout,
    redirect: '/people/personnelList',
    name: 'People',
    meta: { title: '人员管理', icon: 'el-icon-user' },
    children: [
      {
        path: 'personnellist',
        name: 'personnelList',
        component: () => import('@/views/people/personnelList'),
        meta: { title: '人员列表' }
      },
      {
        path: 'peoplecounting',
        name: 'PeopleCounting',
        component: () => import('@/views/people/peopleCounting'),
        meta: { title: '人数统计' }
      },
      {
        path: 'workloadlist',
        name: 'WorkloadList',
        component: () => import('@/views/people/WorkloadList'),
        meta: { title: '工作量列表' }
      }
    ]
  },
  {
    path: '/goods',
    component: Layout,
    redirect: '/Goods/goodstype',
    name: 'Goods',
    meta: { title: '商品管理', icon: 'el-icon-s-goods' },
    children: [
      {
        path: 'goodstype',
        name: 'Goodstype',
        component: () => import('@/views/Goods/goodstype'),
        meta: { title: '商品类型' }
      },
      {
        path: 'goodsmanagement',
        name: 'GoodsManagement',
        component: () => import('@/views/Goods/goodsmanagement'),
        meta: { title: '商品管理' }
      }
    ]
  },
  {
    path: '/strategic',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Strategic',
        component: () => import('@/views/strategic/index'),
        meta: { title: '策略管理', icon: 'el-icon-magic-stick' }
      }
    ]
  },
  {
    path: '/order',
    component: Layout,
    children: [
      {
        path: 'order',
        name: 'Order',
        component: () => import('@/views/order/index'),
        meta: { title: '订单管理', icon: 'el-icon-document' }
      }
    ]
  },
  {
    path: '/statistics',
    component: Layout,
    children: [
      {
        path: 'statistics',
        name: 'Statistics',
        component: () => import('@/views/statistics/index'),
        meta: { title: '对账统计', icon: 'el-icon-money' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
